package Server;

import java.io.IOException;
import java.io.ObjectOutputStream;

import comunicationFrames.Message;

public class ClientHandler extends Thread {

	private ObjectOutputStream socketWriter;

	public ClientHandler(ObjectOutputStream writer) {
		socketWriter = writer;
	}

	public void sendMessage(Message m) {
		try {
			socketWriter.writeObject(m);
		} catch (IOException e) {
			System.err.println("ClientHandler: Error sending message:" + e);
		}
	}

	public void close() {
		try {
			if (socketWriter != null) {
				socketWriter.close();
			}
		} catch (IOException e) {
			System.err.println("ClientHandler: Couldn't close stream:" + e);
		}
	}

	@Override
	protected void finalize() throws Throwable {
		close();
		super.finalize();
	}
}
